  #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
  CBUFFER_START(UnityPerMaterial)
    float4 _CustomCubeTex_HDR;
    half4 _BaseColor;
    half4 _BaseMap_ST;
    half _BumpScale;
    half _OcclusionStrength;
 
    half4 _EmissionColor;
    half _Cutoff;
    half _Smoothness;
    half _Metallic;
    half _SpecPower;
   // #ifdef _SSS

    /*half4 _SssColor;
    half _SssRad;
    half _SssAmb;*/

    half _CustomGGX;
    /*half _PrimaryShift;
    half _AnisoPower;
    half4 _AnisoGlass;*/
    half _BackLight;
    half _SpecularMaxLimit;
    half _CustomCubeTexBrightness;
 
    //#endif
CBUFFER_END
TEXTURE2D(_BaseMap);SAMPLER(sampler_BaseMap);
 TEXTURE2D(_MetallicGlossMap);SAMPLER(sampler_MetallicGlossMap);
TEXTURE2D(_BumpMap);        SAMPLER(sampler_BumpMap);
TEXTURE2D(_FlowMap);        SAMPLER(sampler_FlowMap);


half Alpha(half albedoAlpha, half4 color, half cutoff)
{
#if !defined(_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A) && !defined(_GLOSSINESS_FROM_BASE_ALPHA)
    half alpha = albedoAlpha * color.a;
#else
    half alpha = color.a;
#endif

#if defined(_ALPHATEST_ON)
    clip(alpha - cutoff);
#endif

    return alpha;
}
half4 SampleAlbedoAlpha(float2 uv, TEXTURE2D_PARAM(albedoAlphaMap, sampler_albedoAlphaMap))
{
    return half4(SAMPLE_TEXTURE2D(albedoAlphaMap, sampler_albedoAlphaMap, uv));
}
 
 #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
 #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
 #include "lch_pbr.hlsl"


 #if defined(  ANISOTROPIC_FLOWMAP)
    #define BITANGENT_SPACE  
    #define FLOWMAP   
#endif








#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl"


 

half3 SampleNormal(float2 uv, TEXTURE2D_PARAM(bumpMap, sampler_bumpMap), half scale = half(1.0))
{
#ifdef _NORMALMAP
    half4 n = SAMPLE_TEXTURE2D(bumpMap, sampler_bumpMap, uv);
    /*#if BUMP_SCALE_NOT_SUPPORTED
        return UnpackNormal(n);
    #else*/
        return UnpackNormalScale(n, scale);
   // #endif
#else
    return half3(0.0h, 0.0h, 1.0h);
#endif
}
            
half3 GetNormalST(float2 uv)
{
    #ifdef _NORMALMAP
    return SampleNormal(uv, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap), _BumpScale);
    #else
    return  half3(0,0,1);
    #endif
}

half4 SampleMetallicSpecGloss(float2 uv, half albedoAlpha)
{
    half4 specGloss;
    specGloss = SAMPLE_TEXTURE2D(_MetallicGlossMap, sampler_MetallicGlossMap, uv);
    #if _SPECULAR_SETUP
        specGloss.rgb = _SpecColor.rgb;
    #else
        specGloss.r = _Metallic*specGloss.r;
    #endif
    specGloss.a = _Smoothness*specGloss.a;
     
    return specGloss;
}




#if defined( ANISOTROPIC_ON )||defined(  ANISOTROPIC_FLOWMAP)
    #define BITANGENT_SPACE   
#endif
#if defined(  ANISOTROPIC_FLOWMAP)
    #define BITANGENT_SPACE  
    #define FLOWMAP   
#endif
inline void InitializeLchSurfaceData(float2 uv, out LchSurfaceData outSurfaceData)
{

      outSurfaceData. albedo= 0.0;
 
     outSurfaceData.   metallic= 0.0;
     outSurfaceData.   smoothness= 0.0;
     outSurfaceData.  normalTS= 0.0;
     outSurfaceData.  emission= 0.0;
     outSurfaceData.   occlusion= 0.0;
     outSurfaceData.   alpha= 0.0;  

    
    
   
    

    half4 albedoAlpha = SAMPLE_TEXTURE2D( _BaseMap, sampler_BaseMap,uv);
    outSurfaceData.alpha = Alpha(albedoAlpha.a, _BaseColor, _Cutoff);

    half4 specGloss = SampleMetallicSpecGloss(uv, albedoAlpha.a);
    outSurfaceData.albedo = albedoAlpha.rgb * _BaseColor.rgb;

    outSurfaceData.metallic = specGloss.r;
    outSurfaceData.smoothness = specGloss.a;
    outSurfaceData.normalTS = GetNormalST(uv);
    outSurfaceData.occlusion =  1.0f + _OcclusionStrength * (specGloss.g - 1.0f);
    outSurfaceData.emission = outSurfaceData.albedo.rgb*_EmissionColor.rgb*specGloss.b;



    #ifdef _SSS
    outSurfaceData.sssColor = _SssColor;
 
    outSurfaceData.sssAmb =_SssAmb;
    
 
    #endif


    #if defined(ANISOTROPIC_FLOWMAP)
        outSurfaceData.anisoGlass = _AnisoGlass.rgb ;
        outSurfaceData.primaryShift = _PrimaryShift;
 
        outSurfaceData.anisoPower = _AnisoPower;
        half4 n = SAMPLE_TEXTURE2D(_FlowMap, sampler_FlowMap, uv);
        outSurfaceData.anisoDirTS =  n.rgb*2-1;
 
    #elif defined(ANISOTROPIC_ON)  
        outSurfaceData.anisoGlass = _AnisoGlass.rgb ;
        outSurfaceData.primaryShift = _PrimaryShift;
 
        outSurfaceData.anisoPower = _AnisoPower;
        outSurfaceData.anisoDirTS = half3(0.0,1.0,0.0);

    #else
        outSurfaceData.anisoGlass = 0.0;
        outSurfaceData.primaryShift = 0.0;
        outSurfaceData.anisoPower = 0.0;
        outSurfaceData.anisoDirTS = half3(0.0,1.0,0.0);
    #endif

        outSurfaceData.backLight = _BackLight;
    outSurfaceData.maxLimit = _SpecularMaxLimit;
 
} 

